package com.bw.dao.impl;

import com.bw.dao.ReturnDao;
import com.bw.pojo.vo.ReturnVo;

import java.sql.Connection;

public class ReturnDaoImpl extends BaseDao implements ReturnDao {
    @Override
    public Integer addRetrunPurchase(Connection conn, ReturnVo returnVo) {
        String sql = "INSERT INTO t_return (return_number,return_date,amount_paid,amount_payable,remarks,state,supplier_id,uid) " +
                " VALUES (?,?,?,?,?,?,?,?) ";
        Integer integer = baseInsertWithId(conn, sql, "return_id",
                returnVo.getReturnNumber(),
                returnVo.getReturnDate(),
                returnVo.getAmountPaid(),
                returnVo.getAmountPayable(),
                returnVo.getRemarks(),
                returnVo.getState(),
                returnVo.getSupplierId(),
                returnVo.getUid()
        );
        return integer;
    }

    @Override
    public void addReturnGoods(Connection conn, Integer goodsId, Integer returnId, Integer outNum) {
        String sql = "insert into t_return_goods (goods_id,return_id,out_num) VALUES (?,?,?)";
        baseUpdate(conn,sql,goodsId,returnId,outNum);
    }

    @Override
    public void updRetrunGoods(Connection conn, Integer outNum, Integer goodsId) {
        String sql = "update t_goods set inventory_quantity = inventory_quantity-? where goods_id = ?";
        baseUpdate(conn,sql,outNum,goodsId);
    }
}
